package com.longge;

public class IsWinner {
    public int isWinner(int[] player1, int[] player2) {

        int playerScore1 = 0, playerScore2 = 0;
        for (int i = 0; i < player1.length; i++) {
            if (i >= 2 && (player1[i - 1] == 10 || player1[i - 2] == 10)) {
                playerScore1 += 2 * player1[i];
            } else if (i >= 1 && player1[i - 1] == 10) {
                playerScore1 += 2 * player1[i];
            } else {
                playerScore1 += player1[i];
            }

        }
        for (int i = 0; i < player2.length; i++) {
            if (i >= 2 && (player2[i - 1] == 10 || player2[i - 2] == 10)) {
                playerScore2 += 2 * player2[i];
            } else if (i >= 1 && player2[i - 1] == 10) {
                playerScore2 += 2 * player2[i];
            } else {
                playerScore2 += player2[i];
            }

        }
        return playerScore1 > playerScore2 ? 1 : playerScore1 < playerScore2 ? 2 : 0;
    }
}
